<?php
namespace UserApi\Controller;
use Zend\Mvc\Controller\AbstractRestfulController;
use Zend\View\Model\JsonModel;
class ReviewsRatingsApiController extends AbstractRestfulController
{
    public function getList()
    {
    }
    public function get($user_id)
    {
		header('Access-Control-Allow-Origin: *');
		$reviwesTable=$this->getServiceLocator()->get('Models\Model\ReviewsFactory');			
		$getReviewsAndRatings = $reviwesTable->getReviewsAndRatings($user_id)->toarray();
		if(count($getReviewsAndRatings)!=0){
			return new JsonModel(array(
				'output'	=> 'success',
				'data'		=>	json_encode($getReviewsAndRatings),
			));
		}else{
			return new JsonModel(array(
				'output'	=> 'fail',
			));
		}
    }
    public function create($reviewAndRating)
    {
		header('Access-Control-Allow-Origin: *');
		$userMedicineOrderTable=$this->getServiceLocator()->get('Models\Model\UserMedicineOrderFactory');	
		$checkOrderId = $userMedicineOrderTable->checkOrder($reviewAndRating['trackingID']);
		if($checkOrderId!=0){
			$reviwesTable=$this->getServiceLocator()->get('Models\Model\ReviewsFactory');			
			$ratingTable=$this->getServiceLocator()->get('Models\Model\RatingFactory');
			$postReview = $reviwesTable->postReview($reviewAndRating);
			$postRating = $ratingTable->postRating($reviewAndRating);
			if($postRating!=0){
				return new JsonModel(array(
					'output'		=> 'success',
				));
			}else{
				return new JsonModel(array(
					'output'	=> 'fail',
				));
			}
		}else{
			return new JsonModel(array(
				'status'	=>	'Invalid Tracking Id',
			));
		}
    }
    public function update($id, $s_eamil)
    {
		
    }
    public function delete($id)
    {
       
    }
}